from lxml import etree
import aiohttp
import asyncio


async def fun(session, url):
    async with session.get(url) as response:
        html_str = await response.text()
        tree = etree.HTML(html_str)
        items = tree.xpath('//div[@class="quote"]')
        next = tree.xpath('//li[@class="next"]/a')
        for item in items:
            content = item.xpath("./span[@class='text']/text()")[0][1:-1]
            autor = item.xpath(".//small[@class='author']/text()")[0]
            tags = item.xpath(".//a[@class='tag']/text()")
            print(content, autor, tags)
        if next:
            next_url = 'http://quotes.toscrape.com' + next[0].xpath('./@href')[0]
            await fun(session, next_url)
        else:
            return 'over!!!!!!!!!!!!'


async def main():
    async with aiohttp.ClientSession() as session:
        await asyncio.gather(fun(session, 'http://quotes.toscrape.com/page/1/'))


asyncio.run(main())
